package com.px.controller;

import com.px.mapper.ShOrderMapper;
import com.px.pojo.ShOrder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ProviderShOrderController {

    @Resource
    private ShOrderMapper shOrderMapper;

    @PostMapping("/api/provider/selectShOrderList")
    public List<ShOrder> selectShOrderList(@RequestParam String orderNo,
                                               @RequestParam Integer userId,
                                               @RequestParam Integer commodityId,
                                               @RequestParam Double minPrice,
                                               @RequestParam Double maxPrice,
                                               @RequestParam Integer payStatus,
                                               @RequestParam String aliTradeNo,
                                               @RequestParam Integer pageBegin,
                                               @RequestParam Integer pageSize)throws Exception{
        List<ShOrder> shOrders = shOrderMapper.selectShOrderList(orderNo, userId, commodityId, minPrice, maxPrice, payStatus, aliTradeNo, pageBegin, pageSize);
        if("".equals(shOrders) && null == shOrders){
            return null;
        }
        return shOrders;
    }

    @PostMapping("/api/provider/selectShOrderCount")
    public Integer selectShOrderCount(@RequestParam String orderNo,
                                      @RequestParam Integer userId,
                                      @RequestParam Integer commodityId,
                                      @RequestParam Double minPrice,
                                      @RequestParam Double maxPrice,
                                      @RequestParam Integer payStatus,
                                      @RequestParam String aliTradeNo)throws Exception{
        int count = shOrderMapper.selectShOrderCount(orderNo, userId,commodityId,minPrice,maxPrice,payStatus,aliTradeNo);
        if (count > 0) {
            return count;
        }
        return 0;
    }

    @PostMapping("/api/provider/selectShOrder")
    public ShOrder selectShOrder(@RequestParam Integer orderId)throws Exception{
        ShOrder shOrder = shOrderMapper.selectShOrder(orderId);
        if("".equals(shOrder) && null == shOrder){
            return null;
        }
        return shOrder;
    }

    @PostMapping("/api/provider/insertShOrder")
    public Integer insertShOrder(@RequestBody ShOrder shOrder)throws Exception{
        int insert = shOrderMapper.insertShOrder(shOrder);
        if (insert > 0) {
            return insert;
        }
        return 0;
    }

    @PostMapping("/api/provider/updateShOrder")
    public Integer updateShOrder(@RequestBody ShOrder shOrder)throws Exception{
        int update = shOrderMapper.updateShOrder(shOrder);
        if (update > 0) {
            return update;
        }
        return 0;
    }

    @PostMapping("/api/provider/deleteShOrder")
    public Integer deleteShOrder(@RequestParam Integer id)throws Exception{
        int delete = shOrderMapper.deleteShOrder(id);
        if (delete > 0) {
            return delete;
        }
        return 0;
    }
}
